package javbot.gui;

import java.awt.Insets;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JToolBar;

import javbot.gui.actions.CmdClickAction;
import javbot.gui.actions.CmdGoToAction;
import javbot.gui.actions.CmdKeyAction;
import javbot.gui.actions.CmdTypeAction;
import javbot.gui.actions.CmdWaitAction;

public class Toolbar extends JToolBar {

	private static final long serialVersionUID = 114225881415781342L;
	final private JavbotFrame frame;
	private JButton btnCmdKey = null;
	private JButton btnCmdClick = null;
	private JButton btnCmdGoTo = null;
	private JButton btnCmdType = null;
	private JButton btnCmdWait = null;

	public Toolbar(JavbotFrame frame) {
		super();
		this.frame = frame;
		initialize();		
	}

	private void initialize() {
        this.add(getBtnCmdClick());
        this.add(new JToolBar.Separator());
        this.add(getBtnCmdKey());
        this.add(new JToolBar.Separator());
        this.add(getBtnCmdGoTo());
        this.add(new JToolBar.Separator());
        this.add(getBtnCmdType());
        this.add(new JToolBar.Separator());
        this.add(getBtnCmdWait());
        
	}

	private JButton getBtnCmdClick() {
		if (btnCmdClick == null) {
			btnCmdClick = getDefaultButton(new CmdClickAction(frame), "C", "Click");
		}
		return btnCmdClick;
	}

	private JButton getBtnCmdKey() {
		if (btnCmdKey == null) {
			btnCmdKey = getDefaultButton(new CmdKeyAction(frame), "K", "Key");
		}
		return btnCmdKey;
	}

	/**
	 * This method initializes btnCmdGoTo	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnCmdGoTo() {
		if (btnCmdGoTo == null) {
			btnCmdGoTo = getDefaultButton(new CmdGoToAction(frame), "G" , "Go To (X,Y)");
		}
		return btnCmdGoTo;
	}

	/**
	 * This method initializes btnCmdType	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnCmdType() {
		if (btnCmdType == null) {
			btnCmdType = getDefaultButton(new CmdTypeAction(frame), "T", "Type");
		}
		return btnCmdType;
	}

	/**
	 * This method initializes btnCmdWait	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnCmdWait() {
		if (btnCmdWait == null) {
			btnCmdWait = getDefaultButton(new CmdWaitAction(frame), "W", "Wait");
		}
		return btnCmdWait;
	}
	
	private JButton getDefaultButton(Action a, String text, String tooltip) {
		JButton button = new JButton(a);	
		button.setText(text);	
		button.setToolTipText(tooltip);
		button.setMargin(new Insets(3,7,4,7));
		return button;
	}
	
}
